import { Controller, Get, Post, Body, Patch, Param, Delete, UseInterceptors, UploadedFile, BadRequestException } from '@nestjs/common';
import { FileStorageService } from './file-storage.service';
import { UploadFileDto } from "./dto/file.dto"
import { FileInterceptor } from '@nestjs/platform-express';
import { Public } from '@/common/decorators';

@Controller('files')
export class FileStorageController {
  constructor(private readonly fileService: FileStorageService) { }

  @Post('upload')
  @Public()
  @UseInterceptors(FileInterceptor('file'))
  async uploadFile(@UploadedFile() file: Express.Multer.File, @Body() uploadDto: UploadFileDto) {
    if (!file) {
      throw new BadRequestException("文件不能为空")
    }

    return await this.fileService.uploadFile(file, uploadDto);
  }
}
